const NodeCache = require("node-cache");

/**
 * 缓存工具
 */
class CacheUtil {

    static cache = new NodeCache();

    /**
     *
     * @param key
     */
    static get(key) {
        return this.cache.get(key);
    }

    /**
     *
     * @param key
     * @param value
     * @param expiresIn seconds
     * @return {boolean}
     */
    static set(key, value, expiresIn) {

        return this.cache.set(key, value, expiresIn);
    }


    /**
     * 清除所有缓存
     */
    static clear() {
        this.cache.flushAll();
    }

    /**
     * 删除缓存
     * @param key
     * @return {number}
     */
    static del(...key) {
        return this.cache.del(key);
    }


}

module.exports = CacheUtil
